package com.recombination;

import com.adaptor.Duck;
import com.recombination.duck.DuckCall;
import com.recombination.duck.MallardDuck;
import com.recombination.duck.RedheadDuck;
import com.recombination.duck.RubberDuck;
import com.recombination.factory.AbstractDuckFactory;
import com.recombination.factory.CountingDuckFactory;
import com.recombination.goose.Goose;
import com.recombination.goose.GooseAdapter;

public class DuckSimulator {
    public static void main(String[] args) {
        DuckSimulator duckSimulator = new DuckSimulator();
        AbstractDuckFactory duckFactory = new CountingDuckFactory();
        duckSimulator.simulate(duckFactory);
    }

    private void simulate(AbstractDuckFactory duckFactory){
        Quackable redheadDuck = duckFactory.createRedheadDuck();
        Quackable duckCall = duckFactory.createDuckCall();
        Quackable rubberDuck = duckFactory.createRubberDuck();
        Quackable gooseAdapter = new GooseAdapter(new Goose());
        System.out.println("\nDuck simulator: With Composite - Flocks");

        Flock flockOfDucks = new Flock();
        flockOfDucks.add(redheadDuck);
        flockOfDucks.add(duckCall);
        flockOfDucks.add(rubberDuck);
        flockOfDucks.add(gooseAdapter);

        Quackable mallardOne = duckFactory.createMallardDuck();
        Quackable mallardTwo = duckFactory.createMallardDuck();
        Quackable mallardThree = duckFactory.createMallardDuck();
        Quackable mallardFour = duckFactory.createMallardDuck();

        Flock flockofMallards = new Flock();
        flockofMallards.add(mallardOne);
        flockofMallards.add(mallardTwo);
        flockofMallards.add(mallardThree);
        flockofMallards.add(mallardFour);
        flockOfDucks.add(flockofMallards);

        System.out.println("\nDuck simulator: Whole Flock Simulation");
        simulate(flockOfDucks);
        System.out.println("\nDuck simulator: Mallard Flock Simulation");
        simulate(flockofMallards);
        System.out.println("\nThe ducks quacked " + QuackCounter.getNumberOfQuacks());

    }

    private void simulate(Quackable duck){
        duck.quack();
    }
}
